package com.ruoyi.web.controller.fire;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.fire.domain.TFloor;
import com.ruoyi.fire.service.ITFloorService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 楼层信息Controller
 *
 * @author ruoyi
 * @date 2025-11-02
 */
@RestController
@RequestMapping("/system/floor")
@Api(value = "TFloorController", tags = "楼层信息")
public class TFloorController extends BaseController {
    @Autowired
    private ITFloorService tFloorService;

    /**
     * 查询楼层信息列表
     */
    @ApiOperation("查询楼层信息列表")
    @PreAuthorize("@ss.hasPermi('system:floor:list')")
    @GetMapping("/list")
    public TableDataInfo list(TFloor tFloor) {
        startPage();
        Long userId = SecurityUtils.getUserId();
        if (!SecurityUtils.isAdmin(userId)) {
            tFloor.setCreateUserId(userId);
        }
        List<TFloor> list = tFloorService.selectTFloorList(tFloor);
        return getDataTable(list);
    }

    /**
     * 导出楼层信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:floor:export')")
    @Log(title = "楼层信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TFloor tFloor) {
        List<TFloor> list = tFloorService.selectTFloorList(tFloor);
        ExcelUtil<TFloor> util = new ExcelUtil<TFloor>(TFloor.class);
        util.exportExcel(response, list, "楼层信息数据");
    }

    /**
     * 获取楼层信息详细信息
     */
    @ApiOperation("获取楼层信息详细信息")
    @PreAuthorize("@ss.hasPermi('system:floor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(tFloorService.selectTFloorById(id));
    }

    /**
     * 新增楼层信息
     */
    @ApiOperation("新增楼层信息")
    @PreAuthorize("@ss.hasPermi('system:floor:add')")
    @Log(title = "楼层信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TFloor tFloor) {
        return toAjax(tFloorService.insertTFloor(tFloor));
    }

    /**
     * 修改楼层信息
     */
    @ApiOperation("修改楼层信息")
    @PreAuthorize("@ss.hasPermi('system:floor:edit')")
    @Log(title = "楼层信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TFloor tFloor) {
        return toAjax(tFloorService.updateTFloor(tFloor));
    }

    /**
     * 删除楼层信息
     */
    @ApiOperation("删除楼层信息")
    @PreAuthorize("@ss.hasPermi('system:floor:remove')")
    @Log(title = "楼层信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(tFloorService.deleteTFloorByIds(ids));
    }

    /**
     * 手动同步楼层信息
     */
    @ApiOperation("手动同步楼层信息")
    @Log(title = "手动同步楼层信息", businessType = BusinessType.OTHER)
    @GetMapping("/push/{id}")
    public AjaxResult push(@PathVariable String id) {
        return toAjax(tFloorService.pushTUnit(id));
    }

    /**
     * 远程删除楼层
     */
    @ApiOperation("远程删除楼层")
    @Log(title = "楼层信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/remoteDeletion/{floorId}")
    public AjaxResult remoteDeletion(@PathVariable String floorId) {
        return toAjax(tFloorService.remoteDeletion(floorId));
    }

    /**
     * 先删除远程在删除本地信息
     */
    @ApiOperation("先删除远程在删除本地信息")
    @Log(title = "楼层信息", businessType = BusinessType.OTHER)
    @GetMapping("/remove/{floorId}")
    public AjaxResult removeByFloorId(@PathVariable String floorId) {
        return toAjax(tFloorService.removeByFloorId(floorId));
    }
}
